package com.wannengbang.storemobile.homepage;


import android.os.Bundle;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.wannengbang.storemobile.R;
import com.wannengbang.storemobile.base.BaseActivity;
import com.wannengbang.storemobile.base.DataCallBack;
import com.wannengbang.storemobile.bean.PurchaseDetailsBean;
import com.wannengbang.storemobile.homepage.adapter.PurchaseGoodsListAdapter;
import com.wannengbang.storemobile.homepage.model.HomePageModelImpl;
import com.wannengbang.storemobile.homepage.model.IHomePageModel;
import com.wannengbang.storemobile.utils.DateTimeUtil;
import com.wannengbang.storemobile.utils.NumberFormatUtils;
import com.wannengbang.storemobile.widget.AppTitleBar;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PurchaseDetailsActivity extends BaseActivity {

    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;
    @BindView(R.id.title_bar)
    AppTitleBar titleBar;
    @BindView(R.id.tv_purchaser)
    TextView tvPurchaser;
    @BindView(R.id.tv_goods_total_fee)
    TextView tvGoodsTotalFee;
    @BindView(R.id.tv_order_no)
    TextView tvOrderNo;
    @BindView(R.id.tv_create_time)
    TextView tvCreateTime;
    private IHomePageModel homePageModel;
    private String order_no;
    private PurchaseGoodsListAdapter listAdapter;
    private List<PurchaseDetailsBean.DataBean.ListBean> beanList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_purchase_details);
        ButterKnife.bind(this);
        initView();
    }


    public void initView() {
        homePageModel = new HomePageModelImpl();
        order_no = getIntent().getStringExtra("order_no");
        beanList = new ArrayList<>();
        listAdapter = new PurchaseGoodsListAdapter(beanList);
        recyclerView.setLayoutManager(new LinearLayoutManager(mActivity));
        recyclerView.setAdapter(listAdapter);
        requestStorePurchaseShow();
    }

    /**
     *
     */
    public void requestStorePurchaseShow() {
        homePageModel.requestStorePurchaseShow(order_no, new DataCallBack<PurchaseDetailsBean>() {
            @Override
            public void onSuccessful(PurchaseDetailsBean bean) {
                tvOrderNo.setText(bean.getData().getOrder_no());
                tvPurchaser.setText(bean.getData().getPurchaser());
                String orderFee = NumberFormatUtils.formatDouble(Double.parseDouble(bean.getData().getOrder_fee()) / 100);
                tvGoodsTotalFee.setText(orderFee+"元");
                tvCreateTime.setText(DateTimeUtil.format7(new Date(Long.parseLong(bean.getData().getCreate_time()) * 1000)));
                beanList.addAll(bean.getData().getList());
                listAdapter.notifyDataSetChanged();
            }

            @Override
            public void onFailed(String msg, String code) {

            }
        });
    }
}
